"use strict";
/* eslint-disable @typescript-eslint/no-explicit-any */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = exports.getLogLevel = exports.shouldLog = exports.setLogLevel = exports.setLogger = exports.Logger = exports.stylize = exports.Styles = exports.LOG_LEVEL = void 0;
const chalk_1 = __importDefault(require("chalk"));
exports.LOG_LEVEL = {
    NONE: 0,
    DEBUG: 1,
    LOG: 2,
    WARN: 4,
    ERROR: 8,
};
/**
 * Chalk styles for logger strings.
 */
exports.Styles = {
    debug: chalk_1.default.reset.blue,
    log: chalk_1.default.reset,
    success: chalk_1.default.reset.green,
    info: chalk_1.default.reset.white,
    warn: chalk_1.default.reset.yellow,
    error: chalk_1.default.reset.red,
};
function stylize(label, style, args) {
    const styledLabel = style(label);
    const [firstArg, ...rest] = args;
    if (typeof firstArg === 'string') {
        return [`${styledLabel} ${firstArg}`, ...rest];
    }
    return [styledLabel, ...args];
}
exports.stylize = stylize;
class Logger {
    error(...args) {
        console.error(...stylize('[ERROR]', exports.Styles.error, args));
    }
    warn(...args) {
        console.warn(...stylize('[WARNING]', exports.Styles.warn, args));
    }
    log(...args) {
        console.log(...args);
    }
    success(...args) {
        console.log(...stylize('[SUCCESS]', exports.Styles.success, args));
    }
    info(...args) {
        console.info(...stylize('[INFO]', exports.Styles.info, args));
    }
    debug(...args) {
        console.debug(...stylize('[DEBUG]', exports.Styles.log, args));
    }
    group(...args) {
        console.group(...args);
    }
    groupEnd() {
        console.groupEnd();
    }
}
exports.Logger = Logger;
let currentLogger = new Logger();
let currentLogLevel = exports.LOG_LEVEL.ERROR;
function setLogger(logger) {
    currentLogger = logger;
}
exports.setLogger = setLogger;
function setLogLevel(level) {
    switch (level) {
        case exports.LOG_LEVEL.DEBUG:
            currentLogLevel =
                exports.LOG_LEVEL.DEBUG | exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR;
            break;
        case exports.LOG_LEVEL.LOG:
            currentLogLevel = exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR;
            break;
        case exports.LOG_LEVEL.WARN:
            currentLogLevel = exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR;
            break;
        case exports.LOG_LEVEL.ERROR:
            currentLogLevel = exports.LOG_LEVEL.ERROR;
            break;
        case exports.LOG_LEVEL.NONE:
        default:
            currentLogLevel = exports.LOG_LEVEL.NONE;
    }
}
exports.setLogLevel = setLogLevel;
function shouldLog(level) {
    return !!(currentLogLevel & level);
}
exports.shouldLog = shouldLog;
function getLogLevel() {
    switch (currentLogLevel) {
        case exports.LOG_LEVEL.DEBUG | exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR:
            return exports.LOG_LEVEL.DEBUG;
        case exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR:
            return exports.LOG_LEVEL.LOG;
        case exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR:
            return exports.LOG_LEVEL.WARN;
        case exports.LOG_LEVEL.ERROR:
            return exports.LOG_LEVEL.ERROR;
        default:
            return exports.LOG_LEVEL.NONE;
    }
}
exports.getLogLevel = getLogLevel;
exports.logger = {
    error(...args) {
        if (shouldLog(exports.LOG_LEVEL.ERROR)) {
            currentLogger.error(...args);
        }
    },
    warn(...args) {
        if (shouldLog(exports.LOG_LEVEL.WARN)) {
            currentLogger.warn(...args);
        }
    },
    log(...args) {
        if (shouldLog(exports.LOG_LEVEL.LOG)) {
            currentLogger.log(...args);
        }
    },
    success(...args) {
        if (shouldLog(exports.LOG_LEVEL.LOG)) {
            currentLogger.success(...args);
        }
    },
    info(...args) {
        if (shouldLog(exports.LOG_LEVEL.LOG)) {
            currentLogger.info(...args);
        }
    },
    debug(...args) {
        if (shouldLog(exports.LOG_LEVEL.DEBUG)) {
            currentLogger.debug(...args);
        }
    },
    group(...args) {
        currentLogger.group(...args);
    },
    groupEnd() {
        currentLogger.groupEnd();
    },
};
